package com.office.personalOffice.contacts.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.office.personalOffice.contacts.dao.TbStaffMapper;
import com.office.personalOffice.contacts.pojo.TbStaff;
import com.office.personalOffice.contacts.service.TbStaffService;
import com.office.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 员工服务接口实现类
 * @Auther: 许月
 * @Date: 2022/10/29/15:49
 */
@Service
public class TbStaffServiceImpl implements TbStaffService {

    @Autowired
    private TbStaffMapper tbStaffMapper;


    /**
     * 通过员工id主键获取员工信息
     *
     * @param id
     * @return
     */
    @Override
    public TbStaff getById(Integer id) {
//        System.out.println(id);
        TbStaff tbStaff = tbStaffMapper.queryById(id);
//        System.out.println(tbStaff);
        return tbStaff;
    }


    @Override
    public PageModel<TbStaff> getList(TbStaff tbStaff, PageModel<TbStaff> pageModel) {
        /*System.out.println("***************************************");
        System.out.println(meetroom);
        System.out.println("***************************************");*/

        pageModel.setPageNum(pageModel.getPageNum() <= 0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0?3: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(),pageModel.getPageSize());
        List<TbStaff> tbStaffList = tbStaffMapper.queryList(tbStaff);
        PageInfo<TbStaff> pageInfo = new PageInfo<>(tbStaffList);
        pageModel.setData(tbStaffList);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());
        return pageModel;
    }


}
